<%--
  Created by IntelliJ IDEA.
  User: 隼
  Date: 2017/5/17
  Time: 23:43
  To change this template use File | Settings | File Templates.
  实现网站计数器
  application对象是jsp的一个内置对象
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    int i=0;
    synchronized(application){
        if(application.getAttribute("times")==null){
            i=1;
        }
        else{
            i=Integer.parseInt((String)application.getAttribute("times"));
            i++;
        }
        application.setAttribute("times",Integer.toString(i));
    }
%>
<html>
<head>
    <title>实现网站计数器</title>
</head>
<body>
<center>
    <table height="70" width="200" border="1" bordercolor="black" bordercolorlight="black" bordercolordark="white" cellspacing="0" >
        <tr bgcolor="lightgrey">
            <td align="center">欢迎访问！</td>
        </tr>
        <tr>
            <td align="center">
                您是第<b><%=i%></b>位访问本网站的游客！
            </td>
        </tr>
    </table>
</center>

</body>
</html>
